package 抽象工厂模式;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;


public class ClientGUI extends Application{
             public static void main(String[] args)
             {
            	 launch(args);
             }
             public void start(Stage primaryStage)throws Exception {
                 primaryStage.setTitle("简单工厂方法模式");
                 Button btn = new Button();
                 btn.setText("显示保险信息");
                 
                 Label lab1=new Label("姓名：   詹沛霖    ");
                 Label lab2=new Label("学号：   201627010228 ");
                 Label lab3=new Label("请选择保险类型：  ");
                 ChoiceBox cb1=new ChoiceBox(FXCollections.observableArrayList("PICC-bodyinjur","PICC-cardam","PICC-personinjure","PICC-com","PingAn-bodyinjur","PingAn-cardam","PingAn-personinjure","PingAn-com"));
                 //Image image=new Image("C:\\Users\\Peter D James\\Desktop\\微信图片_20190326204448.jpg");
                 //ImageView ima=new ImageView();
             	//ima.setImage(image);
             	//ima.setFitHeight(200);
             	//ima.setFitWidth(200);
             	
             	TextField txt=new TextField();
             	txt.setMinWidth(250);
             	txt.setMinHeight(200);
            
             	HBox h1=new HBox();
            	 //h1.getChildren().add(ima);
            	 GridPane gri=new GridPane();
            	 gri.setPadding(new Insets(5));
            	 gri.setHgap(5);
            	 gri.setVgap(5);
              
                 gri.add(lab1,1,0,1,1);
                 gri.add(lab2,2,0,1,1);
                 gri.add(lab3, 1,1 );
                 gri.add(cb1, 2,1 );
                 gri.add(btn, 1, 3);
                 FlowPane p1=new FlowPane();
                 p1.getChildren().add(h1);
                 p1.getChildren().add(gri);
                 p1.getChildren().add(txt);
            	 Scene scene=new Scene(p1,600,600);
            	 primaryStage.setScene(scene);
            	 primaryStage.show();
         	
         	 cb1.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener() {
         		@Override
         		public void changed(ObservableValue observable, Object oldValue, Object newValue) {
         	
         			btn.setOnAction(new EventHandler<ActionEvent>() {
         				@Override
         				public void handle(ActionEvent event) {
         					BodyInjure bd=null;
         					CarDam cd=null;
         					PersonInjure pi=null;
         					Com co=null;
         					if(newValue.toString().compareTo("0")==0||newValue.toString().compareTo("1")==0||newValue.toString().compareTo("2")==0||newValue.toString().compareTo("3")==0)
         					{
         					   PICC picc=new PICC();
         					  switch(newValue.toString()) {
         					  case"0":bd=picc.getBd();txt.setText(bd.getInsurInfo());break;
         					  case"1":cd=picc.getCd();txt.setText(cd.getInsurInfo());break;
     						  case"2":pi=picc.getPi();txt.setText(pi.getInsurInfo());break;
     						  case"3":co=picc.getCo();txt.setText(co.getInsurInfo());break;
     						  
         					 }
         					}
         					else
         					{
         						PA pa=new PA();
             					switch(newValue.toString()) {
             					case"4":bd=pa.getBd();txt.setText(bd.getInsurInfo());break;
             					case"5":cd=pa.getCd();txt.setText(cd.getInsurInfo());break;
         						case"6":pi=pa.getPi();txt.setText(pi.getInsurInfo());break;
         						case"7":co=pa.getCo(	);txt.setText(co.getInsurInfo());break;
         						
             					}
         					}
         				    
         			
         				}
         				
         			});
         	
         		}
         	 });
         }
             
}
